#include "contacts.pb.h"
#include <iostream>

int main()
{
    contacts2::PeopleInfo info;
    info.set_name("陶喆");
    info.set_age(50);

    // 序列化
    std::string info_str;
    if (!info.SerializeToString(&info_str))
    {
        std::cerr << "序列化失败!" << std::endl;
        return -1;
    }
    std::cout << "序列化成功" << info_str << std::endl; // 序列化的结果是二进制序列

    // 反序列化
    contacts2::PeopleInfo info2;
    if (!info2.ParseFromString(info_str))
    {
        std::cerr << "反序列化失败!" << std::endl;
        return -1;
    }
    std::cout << "反序列化成功" << std::endl; // 序列化的结果是二进制序列
    std::cout << "name: " << info2.name() << std::endl
              << "age: " << info2.age() << std::endl;

    return 0;
}